<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<hta:application
		applicationName="JSON Formator"
		caption="true"
		icon="http://getcrx.cn/favicon.ico"
		innerborder="yes"
		border="thick"
		navigable="0"
		windowstate="maximize"
		scroll="0"
	>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="x-ua-compatible" content="ie=edge">
	<title>JSON 格式化工具 Ver<!-- build:ver -->VERSION<!-- endbuild --> By：笃行天下</title>
<style type="text/css">
<!--
body{
	margin:0 auto;
	background-color: #EEECC4;
}
#container{
	margin:0 auto;
	width: 960px;
	width: 100vw;
	height: 100vh;
	overflow: hidden;
}
/*按钮*/
#container .format-json{
	width:950px;
	width: 100vw;
	margin:0 auto;
	font-size:30px;
	padding:15px;
}
#container .textArea textarea {
	background-color: #EEE;
	border:1px solid #CCC;
	width: 100%;
	width: calc( 100vw - 10px );
	min-height: 800px;
	min-height: calc( 100vh - 100px );
	padding:5px;
}
#container .info{
	height:10px;
	font-size:15px;
	text-align:right;
	color:#666;
}
#container .info a{
	text-decoration:none;
	color:#030;
}
-->
</style>
</head>

<body>
<div id="container">
	<div class="btnArea">
		<input class="format-json" type="button" onclick="formatJson()" value="FormatJSON"/>
	</div>
	<div class="bgArea">
		<div class="textArea">
			<textarea id="formated">{"应用名称":"JSON 格式化工具","作者":"死宅程序员","生产日期":"2011.10.11"}
			</textarea>
		</div>
	</div>
	<div class="info">Build by <a href="https://shop108373205.taobao.com" target="_blank" title="订制工具">死宅程序员</a></div>
</div>

<script type="text/javascript">
<!--
(function( win ){
	/*jslint white: true, devel: true, onevar: true, browser: true, undef: true, nomen: true, regexp: true, plusplus: false, bitwise: true, newcap: true, maxerr: 50, indent: 4 */
	var jsl = typeof jsl === 'undefined' ? {} : jsl;

	/**
	 * jsl.format - Provide json reformatting in a character-by-character approach, so that even invalid JSON may be reformatted (to the best of its ability).
	 From :https://github.com/umbrae/jsonlintdotcom/blob/master/c/js/jsl.format.js
	 *
	**/
	jsl.format = (function () {

		function repeat(s, count) {
			return new Array(count + 1).join(s);
		}

		function formatJson(json) {
			var i           = 0,
				il          = 0,
				tab         = "    ",
				newJson     = "",
				indentLevel = 0,
				inString    = false,
				currentChar = null;

			for (i = 0, il = json.length; i < il; i += 1) {
				currentChar = json.charAt(i);

				switch (currentChar) {
				case '{':
				case '[':
					if (!inString) {
						newJson += currentChar + "\n" + repeat(tab, indentLevel + 1);
						indentLevel += 1;
					} else {
						newJson += currentChar;
					}
					break;
				case '}':
				case ']':
					if (!inString) {
						indentLevel -= 1;
						newJson += "\n" + repeat(tab, indentLevel) + currentChar;
					} else {
						newJson += currentChar;
					}
					break;
				case ',':
					if (!inString) {
						newJson += ",\n" + repeat(tab, indentLevel);
					} else {
						newJson += currentChar;
					}
					break;
				case ':':
					if (!inString) {
						newJson += ": ";
					} else {
						newJson += currentChar;
					}
					break;
				case ' ':
				case "\r":
				case "\n":
				case "\t":
					if (inString) {
						newJson += currentChar;
					}
					break;
				case '"':
					if (i > 0 && json.charAt(i - 1) !== '\\') {
						inString = !inString;
					}
					newJson += currentChar;
					break;
				default:
					newJson += currentChar;
					break;
				}
			}

			return newJson;
		}

		return { "formatJson": formatJson };

	}());

	var parser = (function(){
		if( window.JSON && JSON.stringify && JSON.parse){
			return function( text ){
				return JSON.stringify( JSON.parse(text) , null, '\t');
			};
		}else{
			return jsl.format.formatJson;
		}
	})();

	function formatJson(){
		var formated = document.getElementById("formated");
		if(formated.innerText != ""){
			formated.innerText = parser(formated.innerText);
		}
	}

	win.formatJson = formatJson;
	// resizeTo(990,600);
	// moveTo(180,100);

	/*
	 * 工具名称：JSON 格式化工具
	 * 作    者：笃行天下
	 * 创建日期：Ver 1.0.0 2011年10月11日 13:18:34
	 * 更新日期：Ver 1.0.1 2015年7月30日 16:33:04
	 * 更新日期：Ver 1.1.0 2017年6月12日 11:43:53
	 */
 })( window );
//-->
</script>
</body>
</html>